package cn.xinfei.xdecision.common.model.component.scorecard.vo;

import cn.xinfei.xdecision.common.model.component.IgnoredParamCheck;
import cn.xinfei.xdecision.common.model.component.scorecard.ScorecardVersion;
import cn.xinfei.xdecision.common.model.component.strategyout.StrategyOutput;
import cn.xinfei.xdecision.common.utils.enums.enginex.ComponentVersionStatusEnum;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ScorecardVersionVo extends ScorecardVersion implements Serializable {

    @IgnoredParamCheck
    private static final long serialVersionUID = -213821397529963731L;

    private List<ScorecardDimensionVo> scorecardDimension;  // 维度

    private List<StrategyOutput> strategyOutputList;//自定义输出字段

    @IgnoredParamCheck
    private String versionNoDesc;

    /**
     * @see ComponentVersionStatusEnum
     */
    @ApiModelProperty("版本状态描述")
    @IgnoredParamCheck
    private String statusDesc;

    public void recurrenceSetIdIsNull() {
        if (CollectionUtils.isNotEmpty(this.scorecardDimension)) {
            this.scorecardDimension.forEach(this::recurrenceDetail);
        }
        if (CollectionUtils.isNotEmpty(this.strategyOutputList)) {
            this.strategyOutputList.forEach(x -> this.setId(null));
        }
        this.setId(null);
    }

    private void recurrenceDetail(ScorecardDimensionVo scorecardDimensionVo) {
        scorecardDimensionVo.setId(null);
        if (CollectionUtils.isNotEmpty(scorecardDimensionVo.getChildren())) {
            scorecardDimensionVo.getChildren().forEach(x -> x.setId(null));
        }
    }
}
